home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / c / DependantScan.lha / DependantScan / Source / ArgumentsDpS.c next >
C/C++ Source or Header  |  1999-02-20  |  22KB  |  355 lines

  1. #define DEF_ARGUMENTSDPS_C
  2.  
  3. #include <exec/types.h>
  4. #include <workbench/startup.h>
  5. #include <proto/icon.h>
  6. #include <clib/dos_protos.h>
  7. #include <clib/exec_protos.h>
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "DependantScan.h"
  14. #include "ProcessDirectory.h"
  15. #include "RequesterError.h"
  16. #include "LocaleSupport.h"
  17.  
  18. /*
  19.    void parse_scoptions_for_argument(
  20.       char *scoptions_variable,                                the string to look for in the scoptions file
  21.       int argument_number,                                     the argument to assign it to
  22.       char *line_buffer)                                       static buffer (of size PD_PATHMAX) to store lines and variable value
  23.  
  24.    * Description
  25.       This function will attempt to build the name of the scoptions file and get the specified SAS/C variable's value from that file. If
  26.       successful, the DPSArgument[argument_number] variable will be set to the value fetched from the scoptions file.
  27. */
  28. void parse_scoptions_for_argument(
  29.    char *scoptions_variable,                                   /* the string to look for in the scoptions file */
  30.    int argument_number,                                        /* the argument to assign it to */
  31.    char *line_buffer)                                          /* static buffer (of size PD_PATHMAX) to store lines and variable value */
  32. {
  33.    FILE *stream;                                               /* will be connected to the file specified by 'scoptions_name' */
  34.    char scoptions_name[PD_PATHMAX];                            /* name of scoptions file */
  35.    size_t variable_length = strlen(scoptions_variable);        /* remember how long the scoptions variable is */
  36.  
  37.    if (DPSArgument[DPS_ARG_PATH] == NULL)                      /* if the current directory is to be used */
  38.       strcpy(scoptions_name,DPS_SCOPTIONS_FILENAME);           /* then, no path information for the scoptions file should be used */
  39.    else                                                        /* either not the shell or the WB */
  40.       dps_build_path(scoptions_name,DPS_SCOPTIONS_FILENAME);   /* build the name of the scoptions file */
  41.  
  42.    if ((stream = fopen(scoptions_name,"r")) != NULL)           /* if we can open the file */
  43.    {
  44.       while (fgets(line_buffer,PD_PATHMAX,stream))             /* while we can get a line from the file */
  45.       {
  46.          if (!memcmp(line_buffer,scoptions_variable,variable_length))                           /* if this line mentions the variable we are looking for */
  47.          {
  48.             DPSArgument[argument_number] = line_buffer + variable_length;                       /* get the variable's value */
  49.             if (strchr(line_buffer,'\n'))                      /* if the line contains a new-line */
  50.                *strchr(line_buffer,'\n') = '\0';               /* remove the new-line */
  51.  
  52.             break;                                             /* we are done */
  53.          }
  54.       }
  55.  
  56.       fclose(stream);                                          /* clean up after ourselves */
  57.    }
  58. }
  59.  
  60. /*
  61.    void parse_scoptions_for_project(void)
  62.  
  63.    * Description
  64.       This function will attempt to parse the value of DPSArgument[DPS_ARG_PROJECT] from the scoptions file. If successful, the
  65.       DPSArgument[DPS_ARG_PROJECT] variable will be set to the value fetched from the scoptions file.
  66. */
  67. void parse_scoptions_for_project(void)
  68. {
  69.    static char line_buffer[PD_PATHMAX];                        /* required by parse_scoptions_for_argument() */
  70.    parse_scoptions_for_argument(DPS_PROGRAMNAME_STRING,DPS_ARG_PROJECT,line_buffer);            /* actually do the parsing */
  71. }
  72.  
  73. /*
  74.    void parse_scoptions_for_object_dir(void)
  75.  
  76.    * Description
  77.       This function will attempt to parse the value of DPSArgument[DPS_ARG_OBJECT_DIR] from the scoptions file. If successful, the
  78.       DPSArgument[DPS_ARG_OBJECT_DIR] variable will be set to the value fetched from the scoptions file.
  79. */
  80. void parse_scoptions_for_object_dir(void)
  81. {
  82.    static char line_buffer[PD_PATHMAX];                        /* required by parse_scoptions_for_argument() */
  83.    parse_scoptions_for_argument(DPS_OBJECTNAME_STRING,DPS_ARG_OBJECT_DIR,line_buffer);          /* actually do the parsing */
  84. }
  85.  
  86. /*
  87.    BOOL dps_get_shell_arguments(
  88.       struct RDArgs *rdargs)                                   where to place the on-line help
  89.  
  90.    * Description
  91.       This function gets the command-line arguments when the program is spawned from the shell.
  92.  
  93.    * Return Value
  94.       TRUE = successful, a call to FreeArgs() is necessary
  95.       FALSE = unsuccessful, a call to FreeArgs() is not necessary
  96. */
  97. BOOL dps_get_shell_arguments(
  98.    struct RDArgs *rdargs)                                      /* where to place the on-line help */
  99. {
  100.    BOOL free_args_needed = FALSE;                              /* value that is returned, TRUE is good, FALSE is bad */
  101.    char *project;                                              /* tells if the user specified a project name */
  102.    char *object_dir;                                           /* for determining if the user specified an object directory */
  103.    static long files_on_line = DPS_DEFAULT_FILESONLINE;        /* the default number of files per line */
  104.    int index;                                                  /* for accessing our messages */
  105.    char arg_lower_name[40];                                    /* lower case version of a command line option */
  106.    char *arg_type;                                             /* the type of the current argument */
  107.    char *arg_name;                                             /* for pointing to various parts of the the current argument */
  108.    char *next_text;                                            /* where the next bit of text should go */
  109.    int longest_arg_name = 0;                                   /* the length of the longest argument name */
  110.    char *template = NULL;                                      /* the template as supplied to DOS */
  111.  
  112.    if ((rdargs->RDA_ExtHelp = AllocVec(2048,0)) == NULL)       /* if we cannot get some memory for our help text */
  113.       {quick_requester_error(DPS_ERROR_CANNOT_ALLOCATE,DPS_ERROR_CANNOT_ALLOCATE,2048); goto _ABORT;}
  114.  
  115.    if ((template = AllocVec(DPS_LINE_BUFFER_SIZE,0)) == NULL)  /* if we cannot get some memory for the DOS template */
  116.       {quick_requester_error(DPS_ERROR_CANNOT_ALLOCATE,DPS_ERROR_CANNOT_ALLOCATE,DPS_LINE_BUFFER_SIZE); goto _ABORT;}
  117.  
  118.    strcpy(rdargs->RDA_ExtHelp,locale_support_string(DPSCatalog, DPS_MSG_USAGE));                /* intialize the help text */
  119.    next_text = rdargs->RDA_ExtHelp + strlen(rdargs->RDA_ExtHelp);                               /* setup where to start appending information */
  120.  
  121.    for (index = 0; index < DPS_ARG_COUNT; ++index)             /* access all of the command line options */
  122.    {
  123.       arg_type = locale_support_string(DPSCatalog, DPS_ARG_COUNT+1+index);                      /* get the type of argument we are dealing with */
  124.       arg_name = locale_support_string(DPSCatalog, index);     /* get the name of the argument */
  125.  
  126.       if (strlen(arg_name) > longest_arg_name)                 /* if this argument is even longer than the others */
  127.          longest_arg_name = strlen(arg_name);                  /* remember which one is the longest */
  128.  
  129.       if (strstr(arg_type,"/K"))                               /* if this is a key word */
  130.       {
  131.          strcpy(arg_lower_name,arg_name);                      /* get a working copy of the argument name */
  132.          strlwr(arg_lower_name);                               /* convert the copy to lower case */
  133.          next_text += sprintf(next_text," [%s %s]",arg_name,arg_lower_name);
  134.       }
  135.       else if (strstr(arg_type,"/S"))                          /* if this is a switch type argument */
  136.       {
  137.          next_text += sprintf(next_text," [%s]",arg_name);
  138.       }
  139.       else                                                     /* NOTE: handle other cases as needed */
  140.       {
  141.          next_text += sprintf(next_text,"%s",arg_name);
  142.       }
  143.  
  144.       if (index == (DPS_ARG_COUNT/2))                          /* if we are at the half way mark */
  145. /* put a break in the arguments */
  146.          next_text += sprin